clear all 
set more off


* This code creates Table 4.
* These are the aggregate labor market transitions
*     between B (self-emp), W (wage work),  U (unemp), N (inactivity)
*     also creates job-job flows B-->W, W-->B, and W--> new W

use "Transitions_BWUN_JJ.dta", clear 
tempfile data1em
save `data1em'



* PANEL A: Exit rates
local xc = 1
foreach x in BU BN WU WN {

	use `data1em', clear

	keep if trans == "`x'"	

	bys ccode trans: egen xmean = mean(ytrate)
	bys ccode trans: egen gdpmean = mean(AGDP)
	bys ccode trans: gen counter = _n


	reg ytrate lcgdp if trans == "`x'", cluster(ccode)
	sum ytrate if trans == "`x'"

	if `xc' == 1 {
		#delimit ;
		outreg2 using "Figures/Table4A.tex", replace 
		keep(lcgdp) addstat(Sample Average,`r(mean)') nocons label dec(3) adec(3) ctitle("`x'")
		nonotes addnote("\textit{Table notes:} Standard errors clustered by country. *p<.05, **p<.01, ***p<.001.");
		#delimit cr
	}
	else {
		#delimit ;
		outreg2 using "Figures/Table4A.tex", append
		keep(lcgdp) addstat(Sample Average,`r(mean)') nocons label dec(3) adec(3) ctitle("`x'")
		nonotes addnote("\textit{Table notes:} Standard errors clustered by country. *p<.05, **p<.01, ***p<.001.");
		#delimit cr	
	}

	local xc = `xc' + 1
}


* PANEL B: JFR
local xc = 1
foreach x in UB NB UW NW {

	use `data1em', clear

	keep if trans == "`x'"	

	bys ccode trans: egen xmean = mean(ytrate)
	bys ccode trans: egen gdpmean = mean(AGDP)
	bys ccode trans: gen counter = _n


	reg ytrate lcgdp if trans == "`x'", cluster(ccode)
	sum ytrate if trans == "`x'"

	if `xc' == 1 {
		#delimit ;
		outreg2 using "Figures/Table4B.tex", replace 
		keep(lcgdp) addstat(Sample Average,`r(mean)') nocons label dec(3) adec(3) ctitle("`x'")
		nonotes addnote("\textit{Table notes:} Standard errors clustered by country. *p<.05, **p<.01, ***p<.001.");
		#delimit cr
	}
	else {
		#delimit ;
		outreg2 using "Figures/Table4B.tex", append
		keep(lcgdp) addstat(Sample Average,`r(mean)') nocons label dec(3) adec(3) ctitle("`x'")
		nonotes addnote("\textit{Table notes:} Standard errors clustered by country. *p<.05, **p<.01, ***p<.001.");
		#delimit cr	
	}

	local xc = `xc' + 1
}




* job change: B --> W

use `data1em', clear

keep if trans == "BW"	

bys ccode trans: egen xmean = mean(ytrate)
bys ccode trans: egen gdpmean = mean(AGDP)
bys ccode trans: gen counter = _n

reg ytrate lcgdp if trans == "BW", cluster(ccode)
sum ytrate if trans == "BW"

#delimit ;
outreg2 using "Figures/Table4C.tex", replace
keep(lcgdp) addstat(Sample Average,`r(mean)') nocons label dec(3) adec(3) ctitle("S to W")
nonotes addnote("\textit{Table notes:} Standard errors clustered by country. *p<.05, **p<.01, ***p<.001.");
#delimit cr	



* job change: W --> B
use `data1em', clear
keep if trans == "WB"	

bys ccode trans: egen xmean = mean(ytrate)
bys ccode trans: egen gdpmean = mean(AGDP)
bys ccode trans: gen counter = _n


reg ytrate lcgdp if trans == "WB", cluster(ccode)
sum ytrate if trans == "WB"

#delimit ;
outreg2 using "Figures/Table4C.tex", append
keep(lcgdp) addstat(Sample Average,`r(mean)') nocons label dec(3) adec(3) ctitle("`x'")
nonotes addnote("\textit{Table notes:} Standard errors clustered by country. *p<.05, **p<.01, ***p<.001.");
#delimit cr	


* --- w-w job changes
use `data1em', clear
keep if trans == "WWnew"	

bys ccode trans: egen xmean = mean(ytrate)
bys ccode trans: egen gdpmean = mean(AGDP)
bys ccode trans: gen counter = _n

* job-job flow
reg ytrate lcgdp if trans == "WWnew", cluster(ccode)
sum ytrate 

#delimit ;
outreg2 using "Figures/Table4C.tex", append
keep(lcgdp) addstat(Sample Average,`r(mean)') nocons label dec(3) adec(3) ctitle("WWnew")
nonotes addnote("\textit{Table notes:} Standard errors clustered by country. *p<.05, **p<.01, ***p<.001.");
#delimit cr	


